package com.yxdj.feedback.controller;

import com.yxdj.common.core.domain.R;
import com.yxdj.common.core.web.controller.BaseController;
import com.yxdj.common.core.web.domain.AjaxResult;
import com.yxdj.common.core.web.page.TableDataInfo;
import com.yxdj.common.log.annotation.Log;
import com.yxdj.common.log.enums.BusinessType;
import com.yxdj.common.security.annotation.InnerAuth;
import com.yxdj.common.security.annotation.RequiresPermissions;
import com.yxdj.feedback.api.domain.UserReview;
import com.yxdj.feedback.api.dto.UserReviewDto;
import com.yxdj.feedback.api.vo.UserReviewVo;
import com.yxdj.feedback.service.UserReviewService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户评价管理
 */
@Tag(name = "用户评价管理")
@RestController
@RequestMapping("/review")
public class UserReviewController extends BaseController {

    @Autowired
    private UserReviewService userReviewService;


    /**
     * 分页获取用户评价列表
     */
    @Operation(summary = "分页获取用户评价列表")
    @GetMapping("/list")
    public TableDataInfo list(UserReview userReview) {
        startPage();
        List<UserReview> list = userReviewService.getPageList(userReview);
        return getDataTable(list);
    }

    /**
     * 获取用户评价详细信息
     */
    @Operation(summary = "获取用户评价详细信息")
    @GetMapping(value = "/getById/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        //获取用户评价详细信息
        UserReview userReview = userReviewService.getUserReviewDetailById(id);
        return success(userReview);
    }

    /**
     * 新增用户评价
     */
    @Operation(summary = "新增用户评价")
    @Log(title = "用户评价管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserReview userReview) {
        return toAjax(userReviewService.save(userReview));
    }

    /**
     * 修改用户评价
     */
    @Operation(summary = "修改用户评价")
    @Log(title = "用户评价管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserReview userReview) {
        return toAjax(userReviewService.updateById(userReview));
    }

    /**
     * 删除用户评价
     */
    @Operation(summary = "删除用户评价")
    @RequiresPermissions("system:userReview:remove")
    @Log(title = "用户评价管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(userReviewService.removeByIds(ids));
    }

    @InnerAuth
    @Operation(summary = "供微服务内部远程调用根据用户条件获取用户评价列表")
    @PostMapping("/app/getUserReviewList")
    public R<UserReviewVo> getUserReviewList(@RequestBody UserReviewDto userReviewDto) {
        UserReviewVo userReviewVo = userReviewService.getUserReviewList(userReviewDto);
        return R.ok(userReviewVo);
    }
}
